//
//  TbOrderWebViewController.m
//  quxiangtao
//
//  Created by xbmios on 2018/9/27.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "TbOrderWebViewController.h"

@interface TbOrderWebViewController () <UIWebViewDelegate, WKUIDelegate, WKNavigationDelegate>

@end

@implementation TbOrderWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = Colorf2f2f2;
    self.automaticallyAdjustsScrollViewInsets = NO;

    [self.view addSubview:self.webView];
    
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    
}


//- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
//
//    return YES;
//}

- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler {
    
    WKNavigationResponsePolicy actionPolicy = WKNavigationResponsePolicyAllow;
    //这句是必须加上的，不然会异常
    decisionHandler(actionPolicy);
    
}

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    
    WKNavigationActionPolicy actionPolicy = WKNavigationActionPolicyAllow;
    
    decisionHandler(actionPolicy);
    
}


/// 2 页面开始加载
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
    
    
}
//- (void)webViewDidStartLoad:(UIWebView *)webView {
//    
//    
//}

/// 5 页面加载完成之后调用
- (void)webViewDidFinishLoad:(UIWebView *)webView {

    NSString *doc = @"document.documentElement.innerHTML";
//    NSString *doc = @"document.body.outerHTML";

    NSString *str = [self.webView stringByEvaluatingJavaScriptFromString:doc];

    NSLog(@"str:\n%@", str);
    
}


#pragma mark -lazy
- (UIWebView *)webView {

    if (!_webView) {

        _webView = [[UIWebView alloc] init];

        _webView.delegate = self;

        _webView.backgroundColor = Colorf2f2f2;
        _webView.scrollView.scrollEnabled = YES;
        _webView.scrollView.showsVerticalScrollIndicator = NO;
        _webView.scrollView.showsHorizontalScrollIndicator = NO;

        _webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        _webView.scrollView.scrollEnabled = YES;

        if (@available(iOS 11.0 , *)) {

            _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;

        }

    }

    return _webView;
}

#pragma mark -设置
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
//    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = NO;
    
    [self.webView stopLoading];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
